package com.nord.NewsList;

import java.util.HashMap;
import java.util.List;

import com.nord.R;
import com.nord.R.id;
import com.nord.R.layout;
import com.nord.WebTools.HtmlBrowser;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public class NewsListAdapter extends SimpleAdapter {

	Context context;
	List<HashMap<String, String>> data;

	public NewsListAdapter(Context context, List<HashMap<String, String>> data,
			int resource, String[] from, int[] to) {
		super(context, data, resource, from, to);
		this.context = context;
		this.data = data;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

		View rowView = inflater.inflate(R.layout.list_news_list, parent, false);

		final TextView title = (TextView) rowView.findViewById(R.id.title);
		final TextView date = (TextView) rowView.findViewById(R.id.date);
		final TextView author = (TextView) rowView.findViewById(R.id.author);

		title.setText(data.get(position).get("title"));
		date.setText("Skrifuð: " + HtmlBrowser.prettyDate(data.get(position).get("date")));
		author.setText("Höfundur: " + data.get(position).get("author"));
		return rowView;
	}
}
